define(['app'], function(app) {
	'use strict';

	var controller = function controller($scope, Productdetail_recommend ,GoPage, $ionicSlideBoxDelegate, $stateParams,GoDialog,GoShare,GoWapAuth) {
		$scope.goods_id = $stateParams.goods_id;
		
		//加载数据
		$scope.init_data = function(){
			Productdetail_recommend.goods_detail($scope.goods_id,function(data){
				$scope.detail = data;
				$ionicSlideBoxDelegate.$getByHandle('advs-handle').update(); //解决无法加载
				$scope.go_share_wx();
			})
		}
		$scope.init_data();
		
		$scope.recommend_info = function(goods_id){
			GoPage.go_states("recommend_info",{"goods_id":$scope.goods_id});
		}
		//页面离开，分享关闭
		$scope.$on('$ionicView.afterLeave', function() {
			$scope.closeGuidShare();
		}, false);
		//一键分享
		$scope.isHide = true; //默认隐藏
		//显示弹窗
		$scope.show_apply = function() {
			if($scope.openGuidShare()){
				$scope.isHide = false;
			}
		}
		$scope.hide_apply = function() {
			$scope.isHide = true;
		}
		
		//分享（自定义每个页面的参数）
		$scope.go_share = function(index) {
			var param = new Object();
			if($scope.detail) {
				param.title = $scope.detail.name ? $scope.detail.name : undefined;
				param.desc = $scope.detail.brief ? $scope.detail.brief : undefined;
				param.thumb = $scope.detail.title_images ? $scope.detail.title_images[0].image.url : undefined;
				param.link = 'productdetail/' + $scope.goods_id;
			}
			GoShare.do_share(param, index);
		}
		//分享（自定义每个页面的参数）
		$scope.go_share_wx = function() {
			//分享打开
			GoWapAuth.execisoff(false);
			//设置分享
			var param = new Object();
			if($scope.detail) {
				param.title = $scope.detail.name ? $scope.detail.name : undefined;
				param.desc = $scope.detail.brief ? $scope.detail.brief : undefined;
				param.thumb = $scope.detail.title_images ? $scope.detail.title_images[0].image.url : undefined;
				param.link = 'productdetail/' + $scope.goods_id;
			}
			GoWapAuth.execshare(param);
		}
	}

	controller.$inject = ['$scope', 'Productdetail_recommend', 'GoPage', '$ionicSlideBoxDelegate', '$stateParams','GoDialog',"GoShare","GoWapAuth"];

	return app.registerController("productdetail_recommendctrl",controller);
});